## Plot the resultslibrary(ggplot2)## Specify my custom themeMyTheme <-theme(plot.title =element_text(face ="bold", size=13, hjust =0.5),plot.subtitle =element_text(face ="italic"),axis.text=element_text(face ="bold"),legend.text =element_text(face ="bold", size=12))## ========================## WITHOUT LV CONDITION## ========================## WITHOUT LV CONDITION: PRECISIONp1 <- results %>%# exclude LV conditionsfilter(!grepl("LV", condition)) %>%ggplot(aes(x=factor(condition, levels =c("5p_sparse", "5p_dense", "10p_sparse", "10p_dense")), y=average_precision_mean, group = algorithm, colour = algorithm)) +scale_colour_manual(values =c("#FF0000", "#00A08A", "#F2AD00"), name="") +geom_line(aes(group = algorithm)) +geom_point() +# in this case, N = 1000 (hence, sqrt(1000))geom_errorbar(aes(ymin=average_precision_mean-qnorm(0.975)*average_precision_sd/sqrt(1000), ymax=average_precision_mean+qnorm(0.975)*average_precision_sd/sqrt(1000)), width=0.1) +labs(x="", y="", title ="Without a Latent Variable Condition", subtitle ="Without LV_PRECISION") +theme_classic() + MyTheme## WITHOUT LV CONDITION: RECALLp2 <- results %>%# exclude LV conditionsfilter(!grepl("LV", condition)) %>%ggplot(aes(x=factor(condition, levels =c("5p_sparse", "5p_dense", "10p_sparse", "10p_dense")), y=average_recall_mean, group = algorithm, colour = algorithm)) +scale_colour_manual(values =c("#FF0000", "#00A08A", "#F2AD00"), name="") +geom_line(aes(group = algorithm)) +geom_point() +# in this case, N = 1000 (hence, sqrt(1000))geom_errorbar(aes(ymin=average_recall_mean-qnorm(0.975)*average_recall_sd/sqrt(1000), ymax=average_recall_mean+qnorm(0.975)*average_recall_sd/sqrt(1000)), width=0.1) +labs(x="", y="", title ="", subtitle ="Without LV_RECALL") +theme_classic() + MyTheme## WITHOUT LV CONDITION: UNCERTAINTYp3 <- uncertainties %>%# exclude LV conditionsfilter(!grepl("LV", condition)) %>%ggplot(aes(x=factor(condition, levels =c("5psparse", "5pdense", "10psparse", "10pdense")), y=mean, group = algorithm, colour = algorithm)) +scale_colour_manual(values =c("#FF0000", "#00A08A", "#F2AD00"), name="") +geom_line(aes(group = algorithm)) +geom_point() +# in this case, N = 1000 (hence, sqrt(1000))geom_errorbar(aes(ymin=mean-qnorm(0.975)*sd/sqrt(1000), ymax=mean+qnorm(0.975)*sd/sqrt(1000)), width=0.1) +labs(x="", y="", title ="", subtitle ="Without LV_UNCERTAINTY") +theme_classic() + MyTheme## WITHOUT LV CONDITION: SHDp4 <- SHDs %>%# exclude LV conditionsfilter(!grepl("LV", condition)) %>%ggplot(aes(x=factor(condition, levels =c("5psparse", "5pdense", "10psparse", "10pdense")), y=mean, group = algorithm, colour = algorithm)) +scale_colour_manual(values =c("#FF0000", "#00A08A", "#F2AD00"), name="") +geom_line(aes(group = algorithm)) +geom_point() +# in this case, N = 1000 (hence, sqrt(1000)) geom_errorbar(aes(ymin=mean-qnorm(0.975)*sd/sqrt(1000), ymax=mean+qnorm(0.975)*sd/sqrt(1000)), width=0.1) +labs(x="", y="", title ="", subtitle ="Without LV_SHD") +theme_classic() + MyTheme## ========================## WITH LV CONDITION## ========================## WITH LV CONDITION: PRECISIONp5 <- results %>%# exclude LV conditionsfilter(grepl("LV", condition)) %>%ggplot(aes(x=factor(condition, levels =c("5p_LV", "10p_LV")), y=average_precision_mean, group = algorithm, colour = algorithm)) +scale_colour_manual(values =c("#FF0000", "#00A08A", "#F2AD00"), name="") +geom_line(aes(group = algorithm)) +geom_point() +# in this case, N = 1000 (hence, sqrt(1000))geom_errorbar(aes(ymin=average_precision_mean-qnorm(0.975)*average_precision_sd/sqrt(1000), ymax=average_precision_mean+qnorm(0.975)*average_precision_sd/sqrt(1000)), width=0.1) +labs(x="", y="", title ="With a Latent Variable Condition", subtitle ="With LV_PRECISION") +theme_classic() + MyTheme## WITH LV CONDITION: RECALLp6 <- results %>%# exclude LV conditionsfilter(grepl("LV", condition)) %>%ggplot(aes(x=factor(condition, levels =c("5p_LV", "10p_LV")), y=average_recall_mean, group = algorithm, colour = algorithm)) +scale_colour_manual(values =c("#FF0000", "#00A08A", "#F2AD00"), name="") +geom_line(aes(group = algorithm)) +geom_point() +# in this case, N = 1000 (hence, sqrt(1000))geom_errorbar(aes(ymin=average_recall_mean-qnorm(0.975)*average_recall_sd/sqrt(1000), ymax=average_recall_mean+qnorm(0.975)*average_recall_sd/sqrt(1000)), width=0.1) +labs(x="", y="", title ="", subtitle ="With LV_RECALL") +theme_classic() + MyTheme## WITH LV CONDITION: UNCERTAINTYp7 <- uncertainties %>%# exclude LV conditionsfilter(grepl("LV", condition)) %>%ggplot(aes(x=factor(condition, levels =c("5pLV2", "10pLV")), y=mean, group = algorithm, colour = algorithm)) +scale_colour_manual(values =c("#FF0000", "#00A08A", "#F2AD00"), name="") +geom_line(aes(group = algorithm)) +geom_point() +# in this case, N = 1000 (hence, sqrt(1000))geom_errorbar(aes(ymin=mean-qnorm(0.975)*sd/sqrt(1000), ymax=mean+qnorm(0.975)*sd/sqrt(1000)), width=0.1) +labs(x="", y="", title ="", subtitle ="With LV_UNCERTAINTY") +theme_classic() + MyTheme## WITH LV CONDITION: SHDp8 <- SHDs %>%# exclude LV conditionsfilter(grepl("LV", condition)) %>%ggplot(aes(x=factor(condition, levels =c("5pLV2", "10pLV")), y=mean, group = algorithm, colour = algorithm)) +scale_colour_manual(values =c("#FF0000", "#00A08A", "#F2AD00"), name="") +geom_line(aes(group = algorithm)) +geom_point() +# in this case, N = 1000 (hence, sqrt(1000))geom_errorbar(aes(ymin=mean-qnorm(0.975)*sd/sqrt(1000), ymax=mean+qnorm(0.975)*sd/sqrt(1000)), width=0.1) +labs(x="", y="", title ="", subtitle ="With LV_SHD") +theme_classic() + MyTheme# combine plotsggarrange(p1, p5, p2, p6, p3, p7, p4, p8,ncol =2, nrow =4, common.legend =TRUE, legend ="bottom")
Figure 7. Simuation results
3 Empirical Example
See code here.
# empirical data 408 rows by 26 columns (p = 26)mcnally <-read.csv("../data/McNally.csv") # check the data#glimpse(mcnally)skimr::skim(mcnally)
Data summary
Name
mcnally
Number of rows
408
Number of columns
26
_______________________
Column type frequency:
numeric
26
________________________
Group variables
None
Variable type: numeric
skim_variable
n_missing
complete_rate
mean
sd
p0
p25
p50
p75
p100
hist
onset
0
1
1.20
1.07
0
0
1
2.00
3
▇▆▁▆▃
middle
0
1
1.44
1.07
0
0
2
2.00
3
▆▃▁▇▃
late
0
1
0.81
1.07
0
0
0
2.00
3
▇▂▁▂▂
hypersom
0
1
1.01
0.99
0
0
1
2.00
3
▇▇▁▅▂
sad
0
1
1.55
0.94
0
1
2
2.00
3
▃▇▁▇▅
decappetite
0
1
0.49
0.73
0
0
0
1.00
3
▇▃▁▁▁
incappetite
0
1
0.44
0.87
0
0
0
0.00
3
▇▁▁▁▁
weightloss
0
1
0.50
0.94
0
0
0
1.00
3
▇▁▁▁▁
weightgain
0
1
0.67
1.04
0
0
0
1.00
3
▇▂▁▂▁
concen
0
1
1.48
0.87
0
1
1
2.00
3
▃▇▁▇▂
guilt
0
1
1.56
1.17
0
1
1
3.00
3
▆▇▁▃▇
suicide
0
1
0.63
0.82
0
0
0
1.00
3
▇▅▁▂▁
anhedonia
0
1
1.27
1.05
0
0
1
2.00
3
▇▇▁▅▅
fatigue
0
1
1.33
0.95
0
1
1
2.00
3
▅▇▁▆▃
retard
0
1
0.66
0.81
0
0
0
1.00
3
▇▅▁▂▁
agitation
0
1
1.10
0.93
0
0
1
2.00
3
▅▇▁▃▂
obtime
0
1
2.95
0.89
0
2
3
4.00
4
▁▁▆▇▇
obinterfer
0
1
2.69
0.83
0
2
3
3.00
4
▁▁▆▇▃
obdistress
0
1
2.81
0.76
0
2
3
3.00
4
▁▁▅▇▃
obresist
0
1
1.98
0.93
0
1
2
2.25
4
▁▃▇▃▁
obcontrol
0
1
2.67
0.76
0
2
3
3.00
4
▁▁▆▇▂
comptime
0
1
2.60
0.93
0
2
3
3.00
4
▁▂▇▇▅
compinterf
0
1
2.58
0.88
0
2
3
3.00
4
▁▂▆▇▂
compdis
0
1
2.71
0.84
0
2
3
3.00
4
▁▁▅▇▂
compresis
0
1
2.16
0.89
0
2
2
3.00
4
▁▂▇▅▁
compcont
0
1
2.60
0.76
0
2
3
3.00
4
▁▁▆▇▂
See code here.
# separate dep / ocd symptomsdepression <- mcnally[,1:16]ocd <- mcnally[,17:26]
See code here.
## run ccd algorithm on entire mcnally (discrete)ccd_mcnally <-ccdKP(df=mcnally, dataType ="discrete") matccd_mcnally <-CreateAdjMat(ccd_mcnally, p =26)## run fci algorithm on entire mcnally (discrete)fci_mcnally <-tetradrunner(algoId ='fci', df = mcnally,dataType ='discrete')matfci_mcnally <-CreateAdjMat(fci_mcnally, p =ncol(mcnally))## run ccd on depression symptomsccd_mcnally_dep <-ccdKP(df=depression, dataType ="discrete") mat_mcnally_dep <-CreateAdjMat(ccd_mcnally_dep, p =ncol(depression))## run fci on depression symptomsfci_mcdep <-tetradrunner(algoId ='fci', df = depression,dataType ='discrete')matfci_mcdep <-CreateAdjMat(fci_mcdep, p =ncol(depression))## run ccd on ocd symptomsccd_mcnally_ocd <-ccdKP(df=ocd, dataType ="discrete") mat_mcnally_ocd <-CreateAdjMat(ccd_mcnally_ocd, p =ncol(ocd))## run fci on ocd symptomsfci_mcocd <-tetradrunner(algoId ='fci', df = ocd,dataType ='discrete')matfci_mcocd <-CreateAdjMat(fci_mcocd, p =ncol(ocd))
See code here.
## CCD PAG for the entire McnallyplotPAG(ccd_mcnally, matccd_mcnally)
Figure 8. CCD PAG on entire McNally data
See code here.
## FCI PAG for the entire McnallyplotPAG(fci_mcnally, matfci_mcnally)
Figure 9. FCI PAG on entire McNally data
See code here.
## CCD PAG for the depression symptomsplotPAG(ccd_mcnally_dep, mat_mcnally_dep) ## FCI PAG for the depression symptomsplotPAG(fci_mcdep, matfci_mcdep)## CCD PAG for the ocd symptomsplotPAG(ccd_mcnally_ocd, mat_mcnally_ocd) ## FCI PAG for the ocd symptomsplotPAG(fci_mcocd, matfci_mcocd)
(a) CCD PAG_depression symptoms
(b) FCI PAG_depression symptoms
(c) CCD PAG_OCD symptoms
(d) FCI PAG_OCD symptoms
Figure 10. Separate PAGs on depression and OCD symptoms